using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Icms.Core.Model;
using Icms.Core.Repository;
using Icms.Data;

namespace Icms.WebUI.Controllers
{
    public class ReportTemplateGroupAjaxDropdownController : Controller
    {

        public ActionResult GetItems(int? key)
        {
            using (var db = new Db())
            {
                var list = new List<SelectListItem> {new SelectListItem{Value="", Text = "toate"}};
                var l = db.ReportTemplateGroups.ToList();
                list.AddRange(l.Select(o => new SelectListItem
                                                         {
                                                             Text = o.Name,
                                                             Value = o.Id.ToString(),
                                                             Selected = o.Id == key
                                                         }));

                return Json(list);
            }
        }
    }
}